fix angles by flipping the coordinate system back to its original y
authorMichael Natterer <mitch@imendio.com>
Sun, 10 Jun 2007 16:29:31 +0000 (16:29 +0000)
committerMichael Natterer <mitch@src.gnome.org>
Sun, 10 Jun 2007 16:29:31 +0000 (16:29 +0000)
2007-06-10  Michael Natterer  <mitch@imendio.com>

* gdk/quartz/gdkdrawable-quartz.c (gdk_quartz_draw_arc): fix
angles by flipping the coordinate system back to its original y
direction. The implementtion is still broken for ellipses, will
have to simulate them using bezier curves.

svn path=/trunk/; revision=18095

ChangeLog
gdk/quartz/gdkdrawable-quartz.c

index e0a95bbedbb534d3540e84d1b36f2317f68abfde..fb7ea56cb86d2e4a5b3e4adbe1cc1c3189262e09 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2007-06-10  Michael Natterer  <mitch@imendio.com>
+
+       * gdk/quartz/gdkdrawable-quartz.c (gdk_quartz_draw_arc): fix
+       angles by flipping the coordinate system back to its original y
+       direction. The implementtion is still broken for ellipses, will
+       have to simulate them using bezier curves.
+
 2007-06-10  Cody Russell  <bratsche@gnome.org>
 
        * gdk/win32/gdkevents-win32.c (gdk_pointer_grab):
index 30ac9097821833c48f5502ec492334e6344b5abd..7e1172fc0bd3547d23ada1db6cefcb8060233690 100644 (file)
@@ -173,6 +173,7 @@ gdk_quartz_draw_arc (GdkDrawable *drawable,
 {
   CGContextRef context = gdk_quartz_drawable_get_context (drawable, FALSE);
   float start_angle, end_angle;
+  gboolean clockwise = FALSE;
 
   if (!context)
     return;
@@ -184,20 +185,38 @@ gdk_quartz_draw_arc (GdkDrawable *drawable,
 
   CGContextSaveGState (context);
 
-  start_angle = (2 - (angle1 / (180.0 * 64.0))) * G_PI;
-  end_angle = start_angle - (angle2 / (180.0 * 64.0)) * G_PI;
+  start_angle = angle1 * 2.0 * G_PI / 360.0 / 64.0;
+  end_angle = start_angle + angle2 * 2.0 * G_PI / 360.0 / 64.0;
+
+  /*  angle2 is relative to angle1 and can be negative, which switches
+   *  the drawing direction
+   */
+  if (angle2 < 0)
+    clockwise = TRUE;
+
+  /*  below, flip the coordinate system back to its original y-diretion
+   *  so the angles passed to CGContextAddArc() are interpreted as
+   *  expected
+   *
+   *  FIXME: the implementation below works only for perfect circles
+   *  (width == height). Any other aspect ratio either scales the
+   *  line width unevenly or scales away the path entirely for very
+   *  small line widths (esp. for line_width == 0, which is a hair
+   *  line on X11 but must be approximated with the thinnest possible
+   *  line on quartz).
+   */
 
   if (filled)
     {
       CGContextTranslateCTM (context,
                              x + width / 2.0,
                              y + height / 2.0);
-      CGContextScaleCTM (context, 1.0, (double)height / (double)width);
+      CGContextScaleCTM (context, 1.0, (double)height / (double)width);
 
       CGContextMoveToPoint (context, 0, 0);
       CGContextAddArc (context, 0, 0, width / 2.0,
                       start_angle, end_angle,
-                      TRUE);
+                      clockwise);
       CGContextClosePath (context);
       CGContextFillPath (context);
     }
@@ -206,11 +225,11 @@ gdk_quartz_draw_arc (GdkDrawable *drawable,
       CGContextTranslateCTM (context,
                              x + width / 2.0 + 0.5,
                              y + height / 2.0 + 0.5);
-      CGContextScaleCTM (context, 1.0, (double)height / (double)width);
+      CGContextScaleCTM (context, 1.0, (double)height / (double)width);
 
       CGContextAddArc (context, 0, 0, width / 2.0,
                       start_angle, end_angle,
-                      TRUE);
+                      clockwise);
       CGContextStrokePath (context);
     }